From dc4edfff5a4939ac2cfbcc637425c3008f44ef3b Mon Sep 17 00:00:00 2001 From: robertl Date: Fri, 10 Jan 2003 18:28:02 +0000 Subject: [PATCH] Jumbo patch from Mottram. Fix README. Use sprintf becuase snprintf is unfortunately not in C89. Make testo play nicer with PSP to avoid hyperactive fp differences. tpg.c avoid sign extension. Various style files: don't use %lf. --- gpsbabel/README | 4 +-- gpsbabel/csv_util.c | 62 ++++++++++++++++------------------- gpsbabel/style/README.style | 14 ++++---- gpsbabel/style/csv.style | 4 +-- gpsbabel/style/custom.style | 18 +++++----- gpsbabel/style/dna.style | 4 +-- gpsbabel/style/gpsdrive.style | 4 +-- gpsbabel/style/gpsman.style | 4 +-- gpsbabel/style/nima.style | 4 +-- gpsbabel/style/ozi.style | 8 ++--- gpsbabel/style/s_and_t.style | 4 +-- gpsbabel/style/tiger.style | 4 +-- gpsbabel/style/xmap.style | 4 +-- gpsbabel/testo | 11 ++++--- gpsbabel/tpg.c | 4 +-- 15 files changed, 74 insertions(+), 79 deletions(-) diff --git a/gpsbabel/README b/gpsbabel/README index cab201249..a0c37019e 100644 --- a/gpsbabel/README +++ b/gpsbabel/README @@ -135,8 +135,8 @@ THE FORMATS NOTE: sn* options require use of the '-s' command line option. Example Usage: - gpsbabel -i xsv,style=foo.style -f foo -o xsv,style=bar.style -F bar - gpsbabel -s -i gpx -f foo.gpx -o xsv,style=my.style,snlen=8 -F bar + gpsbabel -i xcsv,style=foo.style -f foo -o xcsv,style=bar.style -F bar + gpsbabel -s -i gpx -f foo.gpx -o xcsv,style=my.style,snlen=8 -F bar MAPSEND diff --git a/gpsbabel/csv_util.c b/gpsbabel/csv_util.c index 03fe2f880..cf5ee4a2f 100644 --- a/gpsbabel/csv_util.c +++ b/gpsbabel/csv_util.c @@ -612,133 +612,127 @@ xcsv_waypt_pr(const waypoint *wpt) if (strcmp(fmp->key, "IGNORE") == 0) { /* IGNORE -- Write the char printf conversion */ - snprintf (buff, sizeof(buff), fmp->printfc, ""); + sprintf(buff, fmp->printfc, ""); } else if (strcmp(fmp->key, "INDEX") == 0) { - snprintf (buff, sizeof(buff), fmp->printfc, index + atoi(fmp->val)); + sprintf(buff, fmp->printfc, index + atoi(fmp->val)); } else if (strcmp(fmp->key, "CONSTANT") == 0) { - snprintf (buff, sizeof(buff), fmp->printfc, fmp->val); + sprintf(buff, fmp->printfc, fmp->val); } else if (strcmp(fmp->key, "SHORTNAME") == 0) { - snprintf (buff, sizeof(buff), fmp->printfc, shortname); + sprintf(buff, fmp->printfc, shortname); } else if (strcmp(fmp->key, "ANYNAME") == 0) { - snprintf (buff, sizeof(buff), fmp->printfc, anyname); + sprintf(buff, fmp->printfc, anyname); } else if (strcmp(fmp->key, "DESCRIPTION") == 0) { - snprintf (buff, sizeof(buff), fmp->printfc, description); + sprintf(buff, fmp->printfc, description); } else if (strcmp(fmp->key, "NOTES") == 0) { - snprintf (buff, sizeof(buff), fmp->printfc, wpt->notes); + sprintf(buff, fmp->printfc, wpt->notes); } else if (strcmp(fmp->key, "URL") == 0) { - snprintf (buff, sizeof(buff), fmp->printfc, wpt->url); + sprintf(buff, fmp->printfc, wpt->url); } else if (strcmp(fmp->key, "URL_LINK_TEXT") == 0) { - snprintf (buff, sizeof(buff), fmp->printfc, wpt->url_link_text); + sprintf(buff, fmp->printfc, wpt->url_link_text); } else if (strcmp(fmp->key, "ICON_DESCR") == 0) { - snprintf (buff, sizeof(buff), fmp->printfc, wpt->icon_descr); + sprintf(buff, fmp->printfc, wpt->icon_descr); } else /* LATITUDE CONVERSION***********************************************/ if (strcmp(fmp->key, "LAT_DECIMAL") == 0) { /* latitude as a pure decimal value */ - snprintf (buff, sizeof(buff), fmp->printfc, - wpt->position.latitude.degrees); + sprintf(buff, fmp->printfc, wpt->position.latitude.degrees); } else if (strcmp(fmp->key, "LAT_DECIMALDIR") == 0) { /* latitude as a decimal value with N/S after it */ - snprintf (buff, sizeof(buff), fmp->printfc, - fabs(wpt->position.latitude.degrees), + sprintf(buff, fmp->printfc, fabs(wpt->position.latitude.degrees), LAT_DIR(wpt->position.latitude.degrees)); } else if (strcmp(fmp->key, "LAT_DIRDECIMAL") == 0) { /* latitude as a decimal value with N/S before it */ - snprintf (buff, sizeof(buff), fmp->printfc, + sprintf(buff, fmp->printfc, LAT_DIR(wpt->position.latitude.degrees), fabs(wpt->position.latitude.degrees)); } else if (strcmp(fmp->key, "LAT_INT32DEG") == 0) { /* latitude as an integer offset from 0 degrees */ - snprintf (buff, sizeof(buff), fmp->printfc, + sprintf(buff, fmp->printfc, dec_to_intdeg(wpt->position.latitude.degrees, 1)); } else /* LONGITUDE CONVERSIONS*********************************************/ if (strcmp(fmp->key, "LON_DECIMAL") == 0) { /* longitude as a pure decimal value */ - snprintf (buff, sizeof(buff), fmp->printfc, - wpt->position.longitude.degrees); + sprintf(buff, fmp->printfc, wpt->position.longitude.degrees); } else if (strcmp(fmp->key, "LON_DECIMALDIR") == 0) { /* latitude as a decimal value with N/S after it */ - snprintf (buff, sizeof(buff), fmp->printfc, + sprintf(buff, fmp->printfc, fabs(wpt->position.longitude.degrees), LON_DIR(wpt->position.longitude.degrees)); } else if (strcmp(fmp->key, "LON_DIRDECIMAL") == 0) { /* latitude as a decimal value with N/S before it */ - snprintf (buff, sizeof(buff), fmp->printfc, + sprintf(buff, fmp->printfc, LON_DIR(wpt->position.longitude.degrees), fabs(wpt->position.longitude.degrees)); } else if (strcmp(fmp->key, "LON_INT32DEG") == 0) { /* longitudee as an integer offset from 0 degrees */ - snprintf (buff, sizeof(buff), fmp->printfc, + sprintf(buff, fmp->printfc, dec_to_intdeg(wpt->position.longitude.degrees, 0)); } else /* DIRECTIONS *******************************************************/ if (strcmp(fmp->key, "LAT_DIR") == 0) { /* latitude N/S as a char */ - snprintf (buff, sizeof(buff), fmp->printfc, - LAT_DIR(wpt->position.latitude.degrees)); + sprintf(buff, fmp->printfc, + LAT_DIR(wpt->position.latitude.degrees)); } else if (strcmp(fmp->key, "LON_DIR") == 0) { /* longitude E/W as a char */ - snprintf (buff, sizeof(buff), fmp->printfc, + sprintf(buff, fmp->printfc, LON_DIR(wpt->position.longitude.degrees)); } else /* ALTITUDE CONVERSIONS**********************************************/ if (strcmp(fmp->key, "ALT_FEET") == 0) { /* altitude in feet as a decimal value */ - snprintf (buff, sizeof(buff), fmp->printfc, + sprintf(buff, fmp->printfc, (wpt->position.altitude.altitude_meters * 3.2808)); } else if (strcmp(fmp->key, "ALT_METERS") == 0) { /* altitude in meters as a decimal value */ - snprintf (buff, sizeof(buff), fmp->printfc, + sprintf(buff, fmp->printfc, wpt->position.altitude.altitude_meters); } else /* TIME CONVERSIONS**************************************************/ if (strcmp(fmp->key, "EXCEL_TIME") == 0) { /* creation time as an excel (double) time */ - snprintf (buff, sizeof(buff), fmp->printfc, - TIMET_TO_EXCEL(wpt->creation_time)); + sprintf(buff, fmp->printfc, TIMET_TO_EXCEL(wpt->creation_time)); } else if (strcmp(fmp->key, "TIMET_TIME") == 0) { /* time as a time_t variable */ - snprintf (buff, sizeof(buff), fmp->printfc, wpt->creation_time); + sprintf(buff, fmp->printfc, wpt->creation_time); } else /* GEOCACHE STUFF **************************************************/ if (strcmp(fmp->key, "GEOCACHE_DIFF") == 0) { /* Geocache Difficulty as a double */ - snprintf (buff, sizeof(buff), fmp->printfc, - wpt->gc_data.diff / 10); + sprintf(buff, fmp->printfc, wpt->gc_data.diff / 10); } else if (strcmp(fmp->key, "GEOCACHE_TERR") == 0) { /* Geocache Terrain as a double */ - snprintf (buff, sizeof(buff), fmp->printfc, - wpt->gc_data.terr / 10); + sprintf(buff, fmp->printfc, wpt->gc_data.terr / 10); } else if (strcmp(fmp->key, "GEOCACHE_TYPE") == 0) { /* Geocache Type TODO */ - snprintf (buff, sizeof(buff), fmp->printfc, "Geocache"); + sprintf(buff, fmp->printfc, "Geocache"); } else { /* this should probably never happen */ } diff --git a/gpsbabel/style/README.style b/gpsbabel/style/README.style index bb56f4c36..1d9e77efe 100644 --- a/gpsbabel/style/README.style +++ b/gpsbabel/style/README.style @@ -36,8 +36,8 @@ HASH # COMMENTS: Anything after a hash (#) on a line is not parsed. For example: #THIS ENTIRE LINE IS A COMMENT. -#FIELD LAT_DECIMAL, "", "%lf" THIS ENTIRE LINE IS A COMMENT -FIELD LAT_DECIMAL, "", "%lf" # ONLY THIS SENTENCE IS A COMMENT. +#FIELD LAT_DECIMAL, "", "%f" THIS ENTIRE LINE IS A COMMENT +FIELD LAT_DECIMAL, "", "%f" # ONLY THIS SENTENCE IS A COMMENT. DEFINING THE LAYOUT OF THE FILE: @@ -188,7 +188,7 @@ The fields used by the XCSV parser are as follows: signed decimal format (i.e. -91.0000). This data is handled internally as a DOUBLE PRECISION FLOAT and requires a FLOATING POINT printf conversion. - example: IFIELD LAT_DECIMAL,"","%lf" + example: IFIELD LAT_DECIMAL,"","%f" o LON_DECIMAL See LAT_DECIMAL, except LON_DECIMAL defines LONGITUDE. @@ -211,8 +211,8 @@ The fields used by the XCSV parser are as follows: character appears before (LAT_DIRDECIMAL) or after (LAT_DECIMALDIR) the decimal number. - example: IFIELD LAT_DECIMALDIR,"","%lf %c" - example: IFIELD LAT_DIRDECIMAL,"","%c %08.5lf" + example: IFIELD LAT_DECIMALDIR,"","%f %c" (writes 31.333 N) + example: IFIELD LAT_DIRDECIMAL,"","%c %f" (writes N 31.333) o LON_DECIMALDIR / LON_DIRDECIMAL Same as LAT_DECIMALDIR / LAT_DIRDECIMAL except LON_ defines LONGITUDE. @@ -223,7 +223,7 @@ The fields used by the XCSV parser are as follows: a SIGNED DOUBLE PRECISION FLOAT and requires a FLOATING POINT printf conversion. - example: IFIELD ALT_FEET,"","%.0lf" + example: IFIELD ALT_FEET,"","%.0f" o ALT_METERS ALT_METERS is identical to ALT_FEET with the exception that the altitude @@ -234,7 +234,7 @@ The fields used by the XCSV parser are as follows: the decimal days since 1/1/1900 and is handled internally as a DOUBLE PRECISION FLOAT and requires a FLOATING POINT printf conversion. - example: IFIELD EXCEL_TIME,"","%11.5lf" + example: IFIELD EXCEL_TIME,"","%11.5f" o TIMET_TIME TIMET_TIME is the waypoint's creation time, if any. This is actually diff --git a/gpsbabel/style/csv.style b/gpsbabel/style/csv.style index 8866a73f4..9236f8983 100644 --- a/gpsbabel/style/csv.style +++ b/gpsbabel/style/csv.style @@ -17,6 +17,6 @@ BADCHARS COMMA # # INDIVIDUAL DATA FIELDS, IN ORDER OF APPEARANCE: # -IFIELD LAT_DECIMAL, "", "%08.5lf" -IFIELD LON_DECIMAL, "", "%08.5lf" +IFIELD LAT_DECIMAL, "", "%08.5f" +IFIELD LON_DECIMAL, "", "%08.5f" IFIELD DESCRIPTION, "", "%s" diff --git a/gpsbabel/style/custom.style b/gpsbabel/style/custom.style index af22154c3..a9fc40b91 100644 --- a/gpsbabel/style/custom.style +++ b/gpsbabel/style/custom.style @@ -22,9 +22,9 @@ PROLOGUE Prologue Line 2 # IFIELD CONSTANT, "", "CONSTANT" IFIELD INDEX, "", "%d" -IFIELD LAT_DECIMAL, "", "%lf" +IFIELD LAT_DECIMAL, "", "%f" IFIELD LAT_DIR, "", "%c" -IFIELD LON_DECIMAL, "", "%lf" +IFIELD LON_DECIMAL, "", "%f" IFIELD LON_DIR, "", "%c" IFIELD ICON_DESCR, "", "%s" IFIELD SHORTNAME, "", "%s" @@ -32,16 +32,16 @@ IFIELD DESCRIPTION, "", "%s" IFIELD NOTES, "", "%s" IFIELD URL, "", "%s" IFIELD URL_LINK_TEXT, "", "%s" -IFIELD ALT_METERS, "", "%lfM" -IFIELD ALT_FEET, "", "%lfF" -IFIELD LAT_DECIMALDIR, "", "%lf/%c" -IFIELD LON_DECIMALDIR, "", "%lf/%c" -IFIELD LAT_DIRDECIMAL, "", "%c/%lf" -IFIELD LON_DIRDECIMAL, "", "%c/%lf" +IFIELD ALT_METERS, "", "%fM" +IFIELD ALT_FEET, "", "%fF" +IFIELD LAT_DECIMALDIR, "", "%f/%c" +IFIELD LON_DECIMALDIR, "", "%f/%c" +IFIELD LAT_DIRDECIMAL, "", "%c/%f" +IFIELD LON_DIRDECIMAL, "", "%c/%f" IFIELD LAT_INT32DEG, "", "%ld" IFIELD LON_INT32DEG, "", "%ld" IFIELD TIMET_TIME, "", "%ld" -IFIELD EXCEL_TIME, "", "%lf" +IFIELD EXCEL_TIME, "", "%f" # EPILOGUE: EPILOGUE Epilogue Line 1 diff --git a/gpsbabel/style/dna.style b/gpsbabel/style/dna.style index d94dc392a..4b68c1466 100644 --- a/gpsbabel/style/dna.style +++ b/gpsbabel/style/dna.style @@ -18,7 +18,7 @@ BADCHARS COMMA # INDIVIDUAL DATA FIELDS, IN ORDER OF APPEARANCE: # IFIELD INDEX, "", "%d" -IFIELD LAT_DECIMAL, "", "%08.5lf" -IFIELD LON_DECIMAL, "", "%08.5lf" +IFIELD LAT_DECIMAL, "", "%08.5f" +IFIELD LON_DECIMAL, "", "%08.5f" IFIELD DESCRIPTION, "", "%s" diff --git a/gpsbabel/style/gpsdrive.style b/gpsbabel/style/gpsdrive.style index e743bcd2a..ced935348 100644 --- a/gpsbabel/style/gpsdrive.style +++ b/gpsbabel/style/gpsdrive.style @@ -16,5 +16,5 @@ BADCHARS ," # INDIVIDUAL DATA FIELDS, IN ORDER OF APPEARANCE: IFIELD ANYNAME, "", "%s" -IFIELD LAT_DECIMAL, "", "%08.5lf" -IFIELD LON_DECIMAL, "", "%08.5lf" +IFIELD LAT_DECIMAL, "", "%08.5f" +IFIELD LON_DECIMAL, "", "%08.5f" diff --git a/gpsbabel/style/gpsman.style b/gpsbabel/style/gpsman.style index e6b74c825..711e6b1e0 100644 --- a/gpsbabel/style/gpsman.style +++ b/gpsbabel/style/gpsman.style @@ -22,8 +22,8 @@ PROLOGUE !W: # IFIELD SHORTNAME, "", "%-8.8s" IFIELD DESCRIPTION, "", "%s" -IFIELD LAT_DIRDECIMAL, "", "%c%lf" -IFIELD LON_DIRDECIMAL, "", "%c%lf" +IFIELD LAT_DIRDECIMAL, "", "%c%f" +IFIELD LON_DIRDECIMAL, "", "%c%f" IFIELD IGNORE, "", "%s" # gpsman.c likes mkshort len = 8, whitespace = 0. diff --git a/gpsbabel/style/nima.style b/gpsbabel/style/nima.style index a9b684528..7cc42c254 100644 --- a/gpsbabel/style/nima.style +++ b/gpsbabel/style/nima.style @@ -18,8 +18,8 @@ PROLOGUE RC UFI UNI DD_LAT DD_LONG DMS_LAT DMS_LONG UTM JOG FC DSG PC CC1 ADM1 A IFIELD IGNORE, "", "%s" # RC IFIELD IGNORE, "", "%s" # UFI IFIELD IGNORE, "", "%s" # UNI -IFIELD LAT_DECIMAL, "", "%lf" # DD_LAT -IFIELD LON_DECIMAL, "", "%lf" # DD_LON +IFIELD LAT_DECIMAL, "", "%f" # DD_LAT +IFIELD LON_DECIMAL, "", "%f" # DD_LON IFIELD IGNORE, "", "%s" # DMS_LAT IFIELD IGNORE, "", "%s" # DMS_LON IFIELD IGNORE, "", "%s" # UTM diff --git a/gpsbabel/style/ozi.style b/gpsbabel/style/ozi.style index 0acea285d..dad2123fa 100644 --- a/gpsbabel/style/ozi.style +++ b/gpsbabel/style/ozi.style @@ -24,9 +24,9 @@ PROLOGUE Reserved 3 # IFIELD INDEX, "1", "%4d" IFIELD SHORTNAME, "", "%-14.14s" -IFIELD LAT_DECIMAL, "", "%11.6lf" -IFIELD LON_DECIMAL, "", "%11.6lf" -IFIELD EXCEL_TIME, "", "%011.5lf" +IFIELD LAT_DECIMAL, "", "%11.6f" +IFIELD LON_DECIMAL, "", "%11.6f" +IFIELD EXCEL_TIME, "", "%011.5f" IFIELD CONSTANT, "0", "%3s" # icon IFIELD CONSTANT, "1", "%2s" # 1 IFIELD CONSTANT, "3", "%2s" # display format opts @@ -36,7 +36,7 @@ IFIELD DESCRIPTION, "", "%-40.40s" IFIELD CONSTANT, "0", "%2s" # pointer direction IFIELD CONSTANT, "0", "%2s" # garmin display flags IFIELD CONSTANT, "0", "%5s" # proximity distance -IFIELD ALT_FEET, "", "%7.0lf" +IFIELD ALT_FEET, "", "%7.0f" IFIELD CONSTANT, "6", "%2s" # waypt name text size IFIELD CONSTANT, "0", "%2s" # bold checkbox IFIELD CONSTANT, "17", "%2s" # symbol size diff --git a/gpsbabel/style/s_and_t.style b/gpsbabel/style/s_and_t.style index 11a418d45..19c5c0a8b 100644 --- a/gpsbabel/style/s_and_t.style +++ b/gpsbabel/style/s_and_t.style @@ -26,8 +26,8 @@ PROLOGUE Name,Latitude,Longitude,Name 2,URL,Type # HAVE OUR WAY WITH THE FORMATTING. # IFIELD SHORTNAME, "", "%s" # Name -IFIELD LAT_DECIMAL, "", "%lf" # Latitude -IFIELD LON_DECIMAL, "", "%lf" # Longitude +IFIELD LAT_DECIMAL, "", "%f" # Latitude +IFIELD LON_DECIMAL, "", "%f" # Longitude IFIELD DESCRIPTION, "", "%s" # Name 2 (Big Description) IFIELD URL, "", "%s" # URL IFIELD IGNORE, "", "" # Holder for Geocache Type diff --git a/gpsbabel/style/tiger.style b/gpsbabel/style/tiger.style index 8254ea974..011705203 100644 --- a/gpsbabel/style/tiger.style +++ b/gpsbabel/style/tiger.style @@ -17,7 +17,7 @@ BADCHARS COLON # # INDIVIDUAL DATA FIELDS, IN ORDER OF APPEARANCE: # -IFIELD LON_DECIMAL, "", "%lf" -IFIELD LAT_DECIMAL, "", "%lf" +IFIELD LON_DECIMAL, "", "%f" +IFIELD LAT_DECIMAL, "", "%f" IFIELD CONSTANT, "redpin", "%s" IFIELD DESCRIPTION, "", "%s" diff --git a/gpsbabel/style/xmap.style b/gpsbabel/style/xmap.style index 7570667f5..f9453416b 100644 --- a/gpsbabel/style/xmap.style +++ b/gpsbabel/style/xmap.style @@ -19,6 +19,6 @@ EPILOGUE END # # INDIVIDUAL DATA FIELDS, IN ORDER OF APPEARANCE: # -IFIELD LAT_DECIMAL, "", "%08.5lf" -IFIELD LON_DECIMAL, "", "%08.5lf" +IFIELD LAT_DECIMAL, "", "%08.5f" +IFIELD LON_DECIMAL, "", "%08.5f" IFIELD DESCRIPTION, "", "%s" diff --git a/gpsbabel/testo b/gpsbabel/testo index 577ab6080..ba1702963 100755 --- a/gpsbabel/testo +++ b/gpsbabel/testo @@ -80,11 +80,12 @@ diff ${TMPDIR}/magfile reference/magfile ${PNAME} -i dna -f reference/dnatest.txt -o dna -F ${TMPDIR}/dnatest.txt diff ${TMPDIR}/dnatest.txt reference/dnatest.txt -# PSP (PocketStreets 2002 Pushpin (.PSP)) file format -rm -f ${TMPDIR}/ps.psp ${TMPDIR}/psp.psp -${PNAME} -i psp -f reference/ps.psp -o psp -F ${TMPDIR}/psp.psp -${PNAME} -i psp -f ${TMPDIR}/psp.psp -o psp -F ${TMPDIR}/ps.psp -diff ${TMPDIR}/ps.psp reference +# PSP (PocketStreets 2002 Pushpin (.PSP)) file format. Use mxf as an +# intermediate format to avoid binary FP anomalies on different platforms. +rm -f ${TMPDIR}/psp.mxf ${TMPDIR}/mxf.psp +${PNAME} -i psp -f reference/ps.psp -o mxf -F ${TMPDIR}/psp.mxf +${PNAME} -i geo -f geocaching.loc -o mxf -F ${TMPDIR}/mxf.psp +diff ${TMPDIR}/psp.mxf ${TMPDIR}/mxf.psp # MXF (Maptech Exchange Format) file format rm -f ${TMPDIR}/mx.mxf ${TMPDIR}/mxf.mxf diff --git a/gpsbabel/tpg.c b/gpsbabel/tpg.c index dc005a383..ad756ea8e 100644 --- a/gpsbabel/tpg.c +++ b/gpsbabel/tpg.c @@ -254,10 +254,10 @@ tpg_waypt_pr(const waypoint *wpt) char *description; /* these unknown 4 are probably point properties (color, icon, etc..) */ - char unknown4[] = { 0x78, 0x56, 0x34, 0x12 }; + unsigned char unknown4[] = { 0x78, 0x56, 0x34, 0x12 }; /* these 2 appear to be constant across test files */ - char unknown2[] = { 0x01, 0x80 }; + unsigned char unknown2[] = { 0x01, 0x80 }; /* this output format pretty much requires a description * and a shortname -- 2.30.2